package com.hyper_yang._05_juc.chap07;

import java.util.concurrent.SynchronousQueue;

public class SynchronousQueueDemo {

    public static void main(String[] args) throws InterruptedException {
        SynchronousQueue<String> synchronousQueue = new SynchronousQueue(); //容量大小为0 生成后需要立即消费。
        //synchronousQueue.put("abc");
        //Object take = synchronousQueue.take();
        //System.out.println("take = " + take);

        new Thread(()->{
            try {
                synchronousQueue.put("abc");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"生产者").start();

        new Thread(()->{
            try {
                String take = synchronousQueue.take();
                System.out.println("take = " + take);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"消费者").start();
    }
}